﻿<style>
  /*.recordTable .el-table__header tr,*/
  /*.recordTable .el-table__header th {*/
  /*  padding: 0;*/
  /*  height: 60px;*/
  /*}*/
  .recordTable .el-table__body tr,
  .recordTable .el-table__body td {
    padding: 0;
  }

  .recordTable .el-table__body td .cell {
    padding: 0;
  }

  .recordTable .el-table__body td .cell .el-input__inner {
    border: 1px solid hsla(0, 0%, 100%, 0) !important;
    border-radius: 0 !important;
    padding: 0 0 0 15px !important;
    background-color: transparent;
    height: 30px;
  }

  .recordTable.el-table th>.cell {
    padding-left: 5px;
    padding-right: 5px;
  }

  .recordTable.el-table .cell-selected {
    background-color: #9ed0ff !important;
  }

  .autofillcontent {
    /*position: absolute;*/
    /*top:0px;*/
    /*left: 0px;*/
    /*margin-top: 110px;*/
    /*height: 100%;*/
    /*width: 100%;*/
  }


  .el-table .buildyear-row {
    background: #FFFAF0;
  }

  .el-table .caculateyear-row {
    background: white;
  }

  #data-tab .el-tabs--border-card>.el-tabs__content {
    padding: 5px;
  }

  #data-tab .el-tabs__item {
    height: 30px;
    line-height: 30px;
  }

  #data-tab .el-tabs__nav-next,
  #data-tab .el-tabs__nav-prev {
    line-height: 30px;
  }

  #data-tab .el-tabs__header.is-top {
    margin: 0;
  }

  #data-tab .el-input-group__append,
  .el-input-group__prepend {
    padding: 0 10px;
  }

  #data-tab .el-input__inner {
    padding: 0 8px;
  }

  .montecarlo .el-form-item {
    margin-bottom: 5px;
  }

  .montecarlo .block {
    border: 1px solid #DCDFE6;
    margin-top: 10px;
    padding: 10px;
    box-sizing: border-box;
    position: relative;
    border-radius: 4px;
  }

  .montecarlo .block-title {
    left: 10px;
    top: -15px;
    background-color: white;
    padding: 5px;
    color: gray;
    position: absolute;
  }

  .mini-input .el-input__inner {
    padding: 0 8px;
  }

  .mini-input .el-button+.el-button {
    margin-left: 5px;
  }

  .mini-input .el-button--small,
  .mini-input .el-button--small.is-round {
    padding: 9px 12px;
  }

  .option-container .el-col {
    height: 40px;
  }
</style>
<template>
  <div style="height: 100%;position: relative;padding:0 10px 0px 10px;box-sizing: border-box;"
    ref="project_invoke_container" v-loading="isLoading" :element-loading-text="loadingText">
    <el-row class="option-container">
      <el-form label-width="100px" size="small" style="width:100%">
        <el-col span="8">
          <el-form-item label="项目名称:">
            <el-input readonly v-model="currentProjectName"></el-input>
          </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="评价名称:">
<!--            <data-select v-if="computeVersion&&computeVersion.id&&!isLoading"-->
<!--                         :data-url="'/compute_version/data?projectId='+currentProject.id+(computeVersion.parentId?('&parentId='+computeVersion.parentId):'')"-->
<!--                         v-model="computeVersion.id"-->
<!--              @change="changeComputeVersion">-->
<!--            </data-select>-->
            <el-select v-if="computeVersionList&&computeVersion&&computeVersion.id&&!isLoading"
                         v-model="computeVersion.id"
                         @change="changeComputeVersion">
              <el-option v-for="item in computeVersionList" :key="item.id" :value="item.id" :label="item.name">
                <span style="float: left" :style="{'padding-left':item.parentId?'20px':'0'}">{{ item.name }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px">{{ markNameMap[item.mark] }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="评价模型:">
            <data-select disabled v-if="computeVersion" v-model="computeVersion.modelId" data-url="/settings/model/publish/data">
            </data-select>
          </el-form-item>
        </el-col>
<!--        <el-col span="4">-->
<!--          <el-form-item label="成本取值标准:">-->
<!--            <data-select data-url="/cost_standard_version/data" value-key="year"-->
<!--                         v-model="computeVersion.costStandardYear" autocomplete="off" placeholder="请输入内容"></data-select>-->
<!--          </el-form-item>-->
<!--        </el-col>-->
        <el-col span="8">
<!--          <el-col span="10">-->
<!--            <el-form-item label="建设期:">-->
<!--              <el-input v-model="computeVersion.buildYearCount" class="mini-input" autocomplete="off" style="width:100px"-->
<!--                placeholder="请输入内容"><template slot="append">年</template></el-input>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col span="8">
            <el-form-item label="评价期:">
              <el-input :readonly="readonly" v-model="computeVersion.evaluationPeriod" class="mini-input" autocomplete="off" style="width:35px"
                placeholder=""></el-input>
            </el-form-item>
          </el-col>
          <el-col span="16">
            <el-form-item label="" label-width="10px">
              开始年
              <el-input v-model="computeVersion.calculateYearStart" :readonly="readonly" class="mini-input" readonly autocomplete="off"
                style="width:60px" @change="createDataList(recordData)" placeholder="开始年"></el-input>
              结束年
              <el-input v-model="computeVersion.calculateYearEnd" :readonly="readonly" class="mini-input" autocomplete="off"
                style="width:60px" @change="createDataList(recordData)" placeholder="结束年"></el-input>
            </el-form-item>
          </el-col>
        </el-col>

        <!--        <el-col span="8">-->
        <!--          -->
        <!--        </el-col>-->
        <el-col span="16" class="mini-input" style="text-align: right">
          <el-checkbox  label="根据经济极限年判断评价期" v-model="computeVersion.cutoff" style="margin-right: 5px;" :disabled="!checkPermission('compute_version:record')"></el-checkbox>
          <template v-if="computeVersion.type=='default'&&computeVersion.mark!='no_project_cost_pull'">
          <el-button type="primary" @click="fillDataToBottom" v-if="checkPermission('compute_version:record')" size="small">向下填充
          </el-button>
           <el-button type="primary" @click="invoke" v-if="checkPermission('compute_version:record')" size="small">开始评价
          </el-button>
          </template>
<!--          <el-button-->
<!--              v-if="invokeState.state=='complete'"-->
<!--              type="success" icon="el-icon-document" :disabled="invokeState.recordChanged||computeVersion.type!='temp'"-->
<!--              @click="saveResult" size="small">保存-->
<!--          </el-button>-->
<!--          <el-button-->
<!--              v-if="invokeState.state=='complete'"-->
<!--              :disabled="invokeState.recordChanged"-->
<!--              type="success" icon="el-icon-document-add" @click="openSaveDlg" size="small">另存为-->
<!--          </el-button>-->
       <el-button v-if="invokeState.state=='complete'" type="primary"
            @click="openMonteCarloDlg" size="small">蒙特卡洛
          </el-button>
          <!--      <el-button v-if="invokeState.state=='complete'" type="primary"
               @click="openMultiPriceDlg" size="small">多油价
             </el-button>-->
          <el-button v-if="checkPermission('compute_version:record')&&invokeState.state=='complete'&&computeVersion.mark=='no_project'" type="primary"
            @click="cashFlowPull"  size="small">拉齐计算
          </el-button>
<!--          <el-button v-if="invokeState.state=='complete'" type="primary"-->
<!--                     @click="createReport" size="small">生成报告-->
<!--          </el-button>-->
<!--          <el-button v-if="invokeState.state=='complete'" type="primary"-->
<!--                     @click="downloadReport" size="small">报告下载-->
<!--          </el-button>-->
          <el-button v-if="invokeState.state=='complete'&&checkPermission('model:create')"
            @click="downloadLog" size="small">日志下载
          </el-button>

<!--          <el-dropdown v-if="invokeState.state=='complete'" style="margin-left:5px;" @command="(command)=>{handleCommand(command)}">-->
<!--            <el-button style="padding-left: 10px;padding-right: 5px;" size="small">-->
<!--              更多<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
<!--            </el-button>-->
<!--            <el-dropdown-menu slot="dropdown">-->
<!--&lt;!&ndash;                <el-dropdown-item v-if="invokeState.state=='complete'"&ndash;&gt;-->
<!--&lt;!&ndash;                           command="openMonteCarloDlg">蒙特卡洛分析&ndash;&gt;-->
<!--&lt;!&ndash;                </el-dropdown-item>&ndash;&gt;-->
<!--&lt;!&ndash;                <el-dropdown-item v-if="invokeState.state=='complete'"&ndash;&gt;-->
<!--&lt;!&ndash;                                  command="openMultiPriceDlg">多油价计算&ndash;&gt;-->
<!--&lt;!&ndash;                </el-dropdown-item>&ndash;&gt;-->
<!--                <el-dropdown-item v-if="invokeState.state=='complete'&&checkPermission('model:create')"-->
<!--                                  command="downloadLog">日志下载-->
<!--                </el-dropdown-item>-->
<!--                <el-dropdown-item v-if="invokeState.state=='complete'"-->
<!--                                  command="downloadFile">导出结果-->
<!--                </el-dropdown-item>-->
<!--&lt;!&ndash;              <el-dropdown-item command="copy">复制</el-dropdown-item>&ndash;&gt;-->
<!--&lt;!&ndash;              <el-dropdown-item command="export">导出</el-dropdown-item>&ndash;&gt;-->
<!--&lt;!&ndash;              <el-dropdown-item command="delete">删除</el-dropdown-item>&ndash;&gt;-->
<!--            </el-dropdown-menu>-->
<!--          </el-dropdown>-->
          <el-button v-if="invokeState.state=='complete'" type="primary" @click="downloadFile"
            size="small">导出
          </el-button>
<!--          <el-button v-if="invokeState.state=='complete'&&!computeVersion.parentId" type="primary" @click="downloadReportFile"-->
<!--            size="small">报告生成-->
<!--          </el-button>-->
          <el-button
            v-if="invokeState.state=='complete'&&currentProject.state=='audit'&&computeVersion.type=='report'&&checkPermission('evaluation:audit')"
            type="primary" @click="auditVersion(true)" size="small">审核通过
          </el-button>
          <el-button
            v-if="invokeState.state=='complete'&&currentProject.state=='audit'&&computeVersion.type=='report'&&checkPermission('evaluation:audit')"
            type="danger" @click="auditVersion(false)" size="small">退回
          </el-button>
          <!--        </div>-->
        </el-col>
      </el-form>
    </el-row>

    <div style="position: relative;" class="invoke-div">
      <el-tabs id="data-tab" tab-position="top" v-model="invokeState.display">
        <el-tab-pane label="录入参数" name="record" :lazy="true">
          <div>
            <el-tabs type="border-card" @tab-click="changeInputTab(recordTabName)" v-model="recordTabName"
              class="autofillcontent">
              <el-tab-pane v-for="(table,index) in inputTableList" :key="table.id" :label="table.name" :name="table.name"
                :lazy="true">
                <span v-if="table.icon" slot="label"><i :class="table.icon"></i> {{table.name}}</span>

                <div v-if="table.single&&recordData!=null" style="overflow-x: auto;width:100%;">
                  <el-form :model="recordData" :style="'min-width:'+((formLabelWidth+100)*table.displayColumn)+'px;'">
                    <el-col v-for="(field,index) in table.fieldList.filter((item)=>{return item.show;})" :key="field.id"
                      :style="index%table.displayColumn==0?'width:'+(100/table.displayColumn)+'%;clear:both;':'width:'+(100/table.displayColumn)+'%'">
                      <!--                      <el-form-item v-if="invokeState.state=='record'" :label="field.name"-->
                      <el-form-item :label="field.name" :label-width="formLabelWidth+'px'">
                        <template v-if="field.dataType=='boolean'">
                          <el-radio v-model="recordData[table.id][field.id]['-1']" label="true">是</el-radio>
                          <el-radio v-model="recordData[table.id][field.id]['-1']" label="false">否</el-radio>
                        </template>
                        <el-input v-else rows="1" placeholder="" v-model="recordData[table.id][field.id]['-1']">
                          <template v-if="field.unit" slot="append">{{unitTypeMap[field.unit]}}</template>
                        </el-input>
                      </el-form-item>
                      <!--                      <el-form-item v-else :label="field.name" :label-width="formLabelWidth+'px'">-->
                      <!--                        <el-input rows="1" placeholder=""-->
                      <!--                                  disabled-->
                      <!--                                  v-model="recordData[table.id][field.id]['-1']">-->
                      <!--                          <template v-if="field.unit" slot="append">{{unitTypeMap[field.unit]}}</template>-->
                      <!--                        </el-input>-->

                      <!--                      </el-form-item>-->
                    </el-col>
                  </el-form>
                </div>
                <el-table v-else-if="recordTabName==table.name" :id="'t'+table.id"  class="recordTable" :data="getYearList(table)" border
                  highlight-current-row
                          style="`border-color:#ccc"
                  :key="'input_'+table.id+'_'+computeVersion.buildYearCount+'_'+computeVersion.calculateYearStart+'_'+computeVersion.calculateYearEnd"
                  :max-height="contentMaxHeight-40" :span-method="param=>recordTableLabelSpanMethod(param,table)"
                  :header-cell-style="discountHeaderStyle1" :row-class-name="recordTableRowClassName"
                          :cell-style="(val) => {return {'border-color':'#ccc'}}"
                  @cell-mouse-enter="(row, column, cell, event)=>handleMouseMove(event,table.id,column.property,row.value)"
                  @mouseleave.native="handleLeaveTable" @copy.native="handleCopy" empty-text="暂无数据">


                  <el-table-column fixed="left" align="center" label="年度" width="100" :column-key="table.id+'_year'">
                    <el-table-column :column-key="table.id+'_year_label'" prop="label" align="center" width="50">
                    </el-table-column>
                    <el-table-column :column-key="table.id+'_year_value'" prop="value" align="center" width="50">
                    </el-table-column>
                  </el-table-column>


                  <el-table-column v-for="field in table.fieldList.filter((item)=>{return item.show;})" :key="field.id" align="center" :label="field.name"
                    :prop="field.id" :width="judgeColumnWidth(field.name)" min-width="40">


                    <template slot="header">
                      <p style="padding: 0px; margin: 0px;">{{field.name}}</p>
                      <p style="padding: 0px; margin: 0px;" v-if="field.unit">({{unitTypeMap[field.unit]}})</p>
                    </template>
                    <template slot-scope="scope">
                      <!--                      <template v-if="invokeState.state=='record'">-->
                      <template>
                        <el-input v-if="recordData!=null&&field.dataType=='number'"
                          :id="'input:'+table.id+':'+field.id+':'+scope.row.value" rows="1" placeholder=""
                          v-model="recordData[table.id][field.id][scope.row.value]"
                          :class="!selectArea||!selectArea.cellMap||!selectArea.cellMap[field.id+':'+scope.row.value]?'':'cell-selected'"
                          @paste.native.capture.prevent="handlePaste($event,table.id,field.id,scope.row.value)"
                          @input="value=>processInputValue(table,field,scope.row.value,value)"
                          @mousedown.native="handleMouseDown($event,table.id,field.id,scope.row.value)"
                          @mouseup.native="handleMouseUp($event,table.id,field.id,scope.row.value)"
                          @keydown.esc.native="handleEscClick($event,table.id,field.id,scope.row.value)"
                          @keydown.delete.native="handleDeleteClick($event,table.id,field.id,scope.row.value)"
                          @keydown.backspace.native="handleDeleteClick($event,table.id,field.id,scope.row.value)"
                          @keydown.enter.native="handleEnterClick($event,table.id,field.id,scope.row.value)"
                          :readonly="scope.row.value=='sum'"
                          @focus="fillDownOption.tableId=table.id,fillDownOption.fieldId=field.id,fillDownOption.year=scope.row.value">
                        </el-input>
                        <el-input v-else-if="recordData!=null" rows="1" placeholder=""
                          :id="'input:'+table.id+':'+field.id+':'+scope.row.value"
                          v-model="recordData[table.id][field.id][scope.row.value]"
                          :class="!selectArea||!selectArea.cellMap||!selectArea.cellMap[field.id+':'+scope.row.value]?'':'cell-selected'"
                          @paste.native.capture.prevent="handlePaste($event,table.id,field.id,scope.row.value)"
                          @mousedown.native="handleMouseDown($event,table.id,field.id,scope.row.value)"
                          @mouseup.native="handleMouseUp($event,table.id,field.id,scope.row.value)"
                          @keydown.esc.native="handleEscClick($event,table.id,field.id,scope.row.value)"
                          @keydown.delete.native="handleDeleteClick($event,table.id,field.id,scope.row.value)"
                          @keydown.backspace.native="handleDeleteClick($event,table.id,field.id,scope.row.value)"
                          @keydown.enter.native="handleEnterClick($event,table.id,field.id,scope.row.value)"></el-input>
                      </template>
                      <span style="display: none">{{recordData[table.id][field.id][scope.row.value]}}</span>
                      <!--                      <template v-else>{{recordData[table.id][field.id][scope.row.value]}}</template>-->
                    </template>

                  </el-table-column>
                </el-table>
              </el-tab-pane>

            </el-tabs>
<!--            <el-button size="small" type="primary" style="position: absolute;top: 0;right: 0" @click="exportExcel(inputTableList,'录入数据导出')">导出</el-button>-->
            <el-button size="small" type="primary" style="display: none;position: absolute;top: 0;right: 0" @click="exportInputData">导出</el-button>

          </div>
        </el-tab-pane>
        <el-tab-pane label="评价结果" :disabled="invokeState.state!='complete'" name="result">

          <excel-view row-selected-color="rgb(151,242,106,0.3)" v-if="exportPreviewData&&exportPreviewData.sheetList" :data="exportPreviewData"
            :max-height="contentMaxHeight" border-color="#ccc"></excel-view>

        </el-tab-pane>
        <el-tab-pane v-if="1==2" label="蒙特卡洛分析" :disabled="invokeState.state!='complete'" name="monte_carlo">
          <el-row class="montecarlo">

            <el-col style="width:200px;">
              <transfer-panel ref="all_risk_panel" height="420px" title="主要风险因素："
                :data="monteCarloConfig.riskItemList.filter(item=>{return item.type=='all'})"></transfer-panel>
            </el-col>
            <el-col style="width:750px;">
              <el-row>
                <el-col style="width:80px;text-align: center;padding:0;">
                  <div style="margin-top: 60px;">
                    <el-button type="primary" @click="updateDistItem('triangular-add')">&gt;&gt;</el-button>
                  </div>
                  <div>
                    <el-button style="margin-top: 10px;" type="primary" @click="updateDistItem('triangular-remove')">
                      &lt;&lt;</el-button>
                  </div>
                </el-col>
                <el-col style="width:300px;">
                  <transfer-panel ref="triangular_risk_panel" height="200px" width="300px" title="三角分布因素："
                    :data="monteCarloConfig.riskItemList.filter(item=>{return item.type=='triangular'})">
                  </transfer-panel>
                </el-col>
                <el-col style="width:350px;padding-left:10px;">
                  <div class="block" style="height: 190px">
                    <div class="block-title">三角分布</div>
                    <el-form :model="monteCarloConfig.triangularSetting" ref="triangular-from" label-suffix=":"
                      label-position="left">
                      <el-form-item label="下限变化率" :label-width="formLabelWidth" prop="lowerLimit">
                        <el-input size="small" v-model="monteCarloConfig.triangularSetting.lowerLimit"
                          autocomplete="off">
                          <template slot="append">%</template>
                        </el-input>
                      </el-form-item>
                      <el-form-item label="最可能" :label-width="formLabelWidth" prop="most">
                        <el-input size="small" v-model="monteCarloConfig.triangularSetting.most" autocomplete="off">
                          <template slot="append">%</template>
                        </el-input>
                      </el-form-item>
                      <el-form-item label="上限变化率" :label-width="formLabelWidth" prop="upperLimit">
                        <el-input size="small" v-model="monteCarloConfig.triangularSetting.upperLimit"
                          autocomplete="off">
                          <template slot="append">%</template>
                        </el-input>
                      </el-form-item>
                    </el-form>
                    <el-row style="text-align:center;">
                      <el-button size="small" type="primary" @click="updateRiskItemSetting('triangular-from')">设定
                      </el-button>
                      <el-button size="small" @click="resetForm('triangular-from')">重置</el-button>
                    </el-row>

                  </div>
                </el-col>

              </el-row>
              <el-row style="margin-top: 10px">
                <el-col style="width:80px;text-align: center;padding:0;">
                  <div style="margin-top: 60px;">
                    <el-button type="primary" @click="updateDistItem('normal-add')">&gt;&gt;</el-button>
                  </div>
                  <div>
                    <el-button style="margin-top: 10px;" type="primary" @click="updateDistItem('normal-remove')">
                      &lt;&lt;</el-button>
                  </div>
                </el-col>
                <el-col style="width:300px;">
                  <transfer-panel ref="normal_risk_panel" height="200px" width="300px" title="正态分布因素："
                    :data="monteCarloConfig.riskItemList.filter(item=>{return item.type=='normal'})"></transfer-panel>
                </el-col>
                <el-col style="width: 350px;padding-left: 10px;">
                  <div class="block" style="height: 190px">
                    <div class="block-title">正态分布</div>
                    <el-form ref="normal-form" :model="monteCarloConfig.normalSetting" label-suffix=":"
                      label-position="left">
                      <el-form-item label="分布算数平均值" :label-width="formLabelWidth" prop="mean">
                        <el-input size="small" v-model="monteCarloConfig.normalSetting.mean" autocomplete="off">
                        </el-input>
                      </el-form-item>
                      <el-form-item label="分布标准差" :label-width="formLabelWidth" prop="std">
                        <el-input size="small" v-model="monteCarloConfig.normalSetting.std" autocomplete="off">
                        </el-input>
                      </el-form-item>
                    </el-form>
                    <el-row style="text-align:center;">
                      <el-button size="small" type="primary" @click="updateRiskItemSetting('normal-form')">设定
                      </el-button>
                      <el-button size="small" @click="resetForm('normal-form')">重置</el-button>
                    </el-row>
                  </div>

                </el-col>

              </el-row>
            </el-col>
          </el-row>

          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="computeMonteCarlo">计 算</el-button>
            <el-button @click="monteCarloConfig.configDlgVisible = false">取 消</el-button>
          </div>
        </el-tab-pane>
        <el-tab-pane v-if="1==2" style="display:none" label="多油价计算" :disabled="invokeState.state!='complete'"
          name="multi_oil">
          <el-row>
            <el-col :span="4" style="font-size: 14px;">
              <p>
                请录入多个油价进行计算，多油价回车换行进行输入，支持复制粘贴
              </p>
              <el-button type="primary" @click="computeMultiPrice" size="small">计 算</el-button>
              <el-input type="textarea" rows="10" v-model="multiPriceConfig.priceList"></el-input>
            </el-col>
            <el-col :span="20">
            </el-col>
          </el-row>

          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="computeMultiPrice">计 算</el-button>
            <el-button @click="multiPriceConfig.configDlgVisible = false">取 消</el-button>
          </div>

        </el-tab-pane>
      </el-tabs>

    </div>
    <el-dialog title="蒙特卡洛分析设置" :visible.sync="monteCarloConfig.configDlgVisible"
      v-loading.fullscreen.lock="monteCarloConfig.isLoading" element-loading-text="正在计算..."
      :close-on-click-modal="false" width="1000px">
      <el-row class="montecarlo">

        <el-col style="width:200px;">
          <transfer-panel ref="all_risk_panel" height="420px" title="主要风险因素："
            :data="monteCarloConfig.riskItemList.filter(item=>{return item.type=='all'})"></transfer-panel>
        </el-col>
        <el-col style="width:750px;">
          <el-row>
            <el-col style="width:80px;text-align: center;padding:0;">
              <div style="margin-top: 60px;">
                <el-button type="primary" @click="updateDistItem('triangular-add')">&gt;&gt;</el-button>
              </div>
              <div>
                <el-button style="margin-top: 10px;" type="primary" @click="updateDistItem('triangular-remove')">
                  &lt;&lt;</el-button>
              </div>
            </el-col>
            <el-col style="width:300px;">
              <transfer-panel ref="triangular_risk_panel" height="200px" width="300px" title="三角分布因素："
                :data="monteCarloConfig.riskItemList.filter(item=>{return item.type=='triangular'})"></transfer-panel>
            </el-col>
            <el-col style="width:350px;padding-left:10px;">
              <div class="block" style="height: 190px">
                <div class="block-title">三角分布</div>
                <el-form :model="monteCarloConfig.triangularSetting" ref="triangular-from" label-suffix=":"
                  label-position="left">
                  <el-form-item label="" prop="lowerLimit">
                    <el-input size="small" v-model="monteCarloConfig.triangularSetting.lowerLimit" autocomplete="off">
                      <template slot="prepend">下限变化率</template>
                      <template slot="append">%</template>
                    </el-input>
                  </el-form-item>
                  <el-form-item label="" prop="most">
                    <el-input size="small" v-model="monteCarloConfig.triangularSetting.most" autocomplete="off">
                      <template slot="prepend">最 可 能</template>
                      <template slot="append">%</template>
                    </el-input>
                  </el-form-item>
                  <el-form-item label="" prop="upperLimit">
                    <el-input size="small" v-model="monteCarloConfig.triangularSetting.upperLimit" autocomplete="off">
                      <template slot="prepend">上限变化率</template>
                      <template slot="append">%</template>
                    </el-input>
                  </el-form-item>
                </el-form>
                <el-row style="text-align:center;">
                  <el-button size="small" type="primary" @click="updateRiskItemSetting('triangular-from')">设定
                  </el-button>
                  <el-button size="small" @click="resetForm('triangular-from')">重置</el-button>
                </el-row>

              </div>
            </el-col>

          </el-row>
          <el-row style="margin-top: 10px">
            <el-col style="width:80px;text-align: center;padding:0;">
              <div style="margin-top: 60px;">
                <el-button type="primary" @click="updateDistItem('normal-add')">&gt;&gt;</el-button>
              </div>
              <div>
                <el-button style="margin-top: 10px;" type="primary" @click="updateDistItem('normal-remove')">&lt;&lt;
                </el-button>
              </div>
            </el-col>
            <el-col style="width:300px;">
              <transfer-panel ref="normal_risk_panel" height="200px" width="300px" title="正态分布因素："
                :data="monteCarloConfig.riskItemList.filter(item=>{return item.type=='normal'})"></transfer-panel>
            </el-col>
            <el-col style="width: 350px;padding-left: 10px;">
              <div class="block" style="height: 190px">
                <div class="block-title">正态分布</div>
                <el-form ref="normal-form" :model="monteCarloConfig.normalSetting" label-suffix=":"
                  label-position="left">
                  <el-form-item label="" prop="mean">
                    <el-input size="small" v-model="monteCarloConfig.normalSetting.mean" autocomplete="off">
                      <template slot="prepend">分布算数平均值</template>
                    </el-input>
                  </el-form-item>
                  <el-form-item label="" prop="std">
                    <el-input size="small" v-model="monteCarloConfig.normalSetting.std" autocomplete="off">
                      <template slot="prepend">分 布 标  准 差</template>
                    </el-input>
                  </el-form-item>
                </el-form>
                <el-row style="text-align:center;">
                  <el-button size="small" type="primary" @click="updateRiskItemSetting('normal-form')">设定</el-button>
                  <el-button size="small" @click="resetForm('normal-form')">重置</el-button>
                </el-row>
              </div>

            </el-col>

          </el-row>
        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="computeMonteCarlo">计 算</el-button>
        <el-button @click="monteCarloConfig.configDlgVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="多油价试算" :visible.sync="multiPriceConfig.configDlgVisible" :close-on-click-modal="false"
      v-loading.fullscreen.lock="multiPriceConfig.isLoading" element-loading-text="正在计算..." width="1200px">
      <el-row>

        <el-col>
          <div  style="font-size:20px;text-align: center;padding-bottom: 10px;width:90%;margin: 0 auto;padding-top:30px">
                  <span style="float:right;padding-right: 20px;margin-top: -20px;padding-bottom:5px;">
                    <font style="font-size: 16px;color: black;font-weight: bold;padding-right: 365px">多油价维护表</font>
                   <el-button type="success" size="small" @click="addMultiPrice">新增</el-button>
                  </span>
            <record-table id="multiPrice" key="multiPrice" border-color="#ccc" :data="multiPriceConfig.priceList" :columns="multiPriceColumns"></record-table>

          </div>
<!--          <div style="font-size:16px;padding-left: 55px;">请录入多个油价进行计算，多油价回车换行进行输入，支持复制粘贴</div>-->
<!--          <el-input type="textarea" rows="10" v-model="multiPriceConfig.priceList"></el-input>-->
        </el-col>
<!--        <el-col :span="13">-->
<!--        </el-col>-->
      </el-row>

      <div slot="footer" style="text-align: center;" class="dialog-footer">
        <el-button type="primary" @click="computeMultiPrice">计 算</el-button>
        <el-button @click="multiPriceConfig.configDlgVisible = false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="蒙特卡洛分析结果" :visible.sync="monteCarloConfig.monteCarloResultVisible" v-loading="monteCarloLoading"
      element-loading-text="正在获取数据..." :close-on-click-modal="false" width="1000px">
      <el-row v-for="item in monteCarloSummaryList" style="text-align: center;">
        <div v-if="monteCarloChartOptionMap[item.ref]">
          <v-chart :option="monteCarloChartOptionMap[item.ref]" style="width:100%;height:250px;"></v-chart>
          <div>{{item.desc}}</div>
        </div>
      </el-row>
      <el-row>
        <el-table border :id="'monte_carlo_summary_table_'+computeVersion.id"
          :data="[{name:'均值',id:'mean'},{name:'中位数',id:'median'},{name:'标准差',id:'std'},{name:'最小值',id:'min'},{name:'最大值',id:'max'}]">
          <el-table-column label="指标" prop="name"></el-table-column>
          <el-table-column v-for="item in monteCarloSummaryList" :label="item.name">
            <template slot-scope="scope">
              {{parseFloat(item[scope.row.id]).toFixed(5)}}
            </template>
          </el-table-column>
        </el-table>

      </el-row>
      <el-row style="display: none;">
        <el-table border id="monte_carlo_data_table"
                  :data="monteCarloItemDataList">
          <el-table-column v-for="item in monteCarloSummaryList" :label="item.name" :prop="item.ref">
            <!--            <template slot-scope="scope">-->
            <!--              {{parseFloat(item[scope.row.id]).toFixed(5)}}-->
            <!--            </template>-->
          </el-table-column>
        </el-table>
<!--        <record-table v-for="item in monteCarloSummaryList" :id="'monte_carlo_rate_analysis_'+item.ref" :columns="[{id:'range',name:'范围',readonly:true},{id:'rate',name:'概率',readonly:true},]"-->
<!--                      :data="monteCarloRateAnalysisMap[item.ref]">-->
<!--        </record-table>-->
        <el-table v-for="item in monteCarloSummaryList" border :id="'monte_carlo_rate_analysis_'+item.ref"
                  :data="monteCarloRateAnalysisMap[item.ref]">
          <el-table-column  label="范围" prop="range">
          </el-table-column>
          <el-table-column  label="概率" prop="rate">
          </el-table-column>
        </el-table>
      </el-row>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="downloadMonteCarloData">导 出</el-button>
        <el-button @click="monteCarloConfig.monteCarloResultVisible = false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog v-loading="isLoading" title="保存评价结果" :visible.sync="detailDlgVisible"
      :close-on-click-modal="false" width="50%">
      <el-form label-width="auto" style="width:100%;margin-top:20px;">
        <el-form-item label="评价名称:">
          <el-input v-model="computeVersion.name" autocomplete="off" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="评价模型:">
<!--          <el-select disabled v-model="computeVersion.modelId" placeholder="请选择">-->
<!--            <el-option v-for="item in modelList" :key="item.id" :label="item.name" :value="item.id">-->
<!--            </el-option>-->
<!--          </el-select>-->
          <data-select disabled v-if="computeVersion" v-model="computeVersion.modelId" data-url="/settings/model/publish/data">
          </data-select>
        </el-form-item>
        <el-row>
          <el-col span="8">
            <el-form-item label="评价期:">
              <el-input readonly v-model="computeVersion.evaluationPeriod" autocomplete="off" placeholder="请输入内容">
                <template slot="append">年</template></el-input>
            </el-form-item>
          </el-col>
          <el-col span="16">
            <el-form-item>
              <el-col span="11">
                <el-input readonly v-model="computeVersion.calculateYearStart" autocomplete="off" placeholder="开始年">
                </el-input>
              </el-col>
              <el-col span="2">~</el-col>

              <el-col span="11">
                <el-input readonly v-model="computeVersion.calculateYearEnd" autocomplete="off" placeholder="结束年">
                </el-input>
              </el-col>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="">
            <el-checkbox label="根据经济极限年判断评价期" disabled v-model="computeVersion.cutoff" style="margin-right: 15px">
            </el-checkbox>
          </el-form-item>
        </el-row>
        <el-form-item label="备注:">
          <el-input type="textarea" v-model="computeVersion.remark" autocomplete="off" placeholder="请输入内容"></el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="copyVersion">保存</el-button>
        <el-button @click="detailDlgVisible = false">取消</el-button>
      </span>
    </el-dialog>

  </div>

</template>

<script>
  import ECharts from "vue-echarts"; // refers to components/ECharts.vue in webpack

  // import ECharts modules manually to reduce bundle size
  import "echarts/lib/chart/line";
  // import "echarts/lib/chart/pie";
  import "echarts/lib/chart/bar";
  import "echarts/lib/component/tooltip";

  import "echarts/lib/component/legend";
  import "echarts/lib/component/title";

  Vue.component("v-chart", ECharts);
  export default {
    name: "ComputeInvoke",
    $$route:{
      meta: {
        title: '评价详情'
      }
    },
    data() {
      return {
        computeVersionList:null, //评价列表
        computeVersionData:[],  //存放this.$get("/compute_version/data")接口中获取的数据
        markNameMap:{            //与上方一块
          'has_project':'有项目版本',
          'no_project':'无项目版本',
          'no_project_cost_pull':'无项目拉齐版本',
          'result':'对减版本',
        },
        sourceComputeVersion: '',
        detailDlgVisible: false,
        isLoading: true,
        loadingText: '正在处理...',
        formLabelWidth: '120px',
        inputTableList: [],
        inputTableMap: {},
        //是否是只读状态，版本上报或退回、审核通过后都不可进行变更
        readonly:false,
        computeVersion: {
          id: '',
          modelId: '',
          name: '',
          type: '',
          cutOff: false,
          buildYearCount: 0,
          calculateYearStart: new Date().getFullYear(),
          calculateYearEnd: new Date().getFullYear() + 15
        },
        currentProject: {
          id: ''
        },
        unitTypeMap: {},
        currentProjectName: '',
        //当前页面状态
        invokeState: {
          //当前状态，默认为录入
          state: 'record',
          //展示标签页，默认展示录入标签页
          display: 'record',
          //录入数据是否发生变更
          recordChanged:false,
        },

        exportPreviewData: {},
        recordData: null,
        recordParam: {},
        recordTabName: 'baseParam',
        // sensAnalysisChart:null,
        // sensAnalysisChartOption:{},
        fillDownOption: {},
        detailCellIndex: '',
        selectArea: {
          cellMap: null
        },
        updateAreaTask: null,
        recordTableLabelSpanCache: {},
        monteCarloConfig: {
          isLoading: false,
          configDlgVisible: false,
          monteCarloResultVisible: false,
          riskItemList: [],
          riskItemMap: {},
          triangularSetting: {
            lowerLimit: '0',
            upperLimit: '0',
            most: '0'
          },
          normalSetting: {
            mean: '0',
            std: '0'
          }

        },
        multiPriceColumns:[
          {name: '序号', id: 'index', readonly: true},
          {name: '油价(元/吨)', id: 'price'},
          {
            name: '操作', type: 'button', id: 'operate', children: [{
              text: '删除', type: 'danger', click: (row) => {
                let list = [];
                for (let item of this.multiPriceConfig.priceList) {
                  if (row.index == item.index) {
                    continue;
                  }
                  list.push(item);

                }
                let newList= [];
                for (let i = 0; i <list.length; i++) {
                  let item = {
                    index: i +1,
                    price: list[i].price
                  }
                  newList.push(item)
                }
                this.multiPriceConfig.priceList=newList;
              }
            }],
          }

        ],
        multiPriceConfig: {
          isLoading: false,
          configDlgVisible: false,
          priceList: [],
        },
        monteCarloSummaryList: [],
        monteCarloChartOptionMap: {},
        //蒙特卡洛各项指标概率分析集合
        monteCarloRateAnalysisMap:{},
        //蒙特卡洛5000次模拟数据列表
        monteCarloItemDataList: [],
      }
    },
    props: {
      pageHeight: {
        type: Number,
        default: 300
      }
    },
    computed: {
      contentMaxHeight: function () {
        return this.pageHeight - 120;
      },

      yearList: function () {

        //设置最大评价50年，防止卡死
        if (this.computeVersion.calculateYearEnd - this.computeVersion.calculateYearStart > 50) {
          this.computeVersion.calculateYearEnd = this.computeVersion.calculateYearStart + 50;
        }

        let list = [];
        for (let i = this.computeVersion.calculateYearStart; i <= this.computeVersion.calculateYearEnd; i++) {
          let label = '生产期';
          if (this.computeVersion.buildYearCount && i < this.computeVersion.buildYearCount + this.computeVersion
            .calculateYearStart) {
            label = '建设期';
          }
          if (this.computeVersion.buildYearCount < 1) {
            label = '评价期';
          }
          list.push({
            label: label,
            value: i
          });
        }
        return list;
      },


      containsLastYearList: function () {
        let list = [];
        list.push({
          label: '已发生',
          value: this.computeVersion.calculateYearStart - 1
        });
        list = list.concat(this.yearList);
        return list;
      }
    },
    watch:{
      $route(to,from) {
        // if(this.computeVersion.id!=to.query.version) {
        //   this.init(this.currentProject.id,to.query.version);
        // }
      }
    },
    created: function () {
      this.$emit('top-menu', '/project/info-list');
    },
    mounted: function () {
      const projectId = this.$route.query.id;
      const version = this.$route.query.version
      this.loadComputeVersionList(projectId);
      this.init(projectId,version);
    },

    methods: {
      //初始化
      init(projectId,version){
        this.initInvokeState();
        this.exportPreviewData = {};
        this.sourceComputeVersion = version;
        // this.isLoading = true;
        this.loadMetaNameMap('unit-type', (map) => {
          this.unitTypeMap = map;
          this.loadProjectInfo(projectId);
          if (version && version.length > 0) {
            //加载版本信息，加载录入模型
            this.loadComputeVersionInfo(version,this.loadInputInfo);
          }
        });
        for (let i = 0; i < 5; i++) {
          this.addMultiPrice();
        }
      },
      getYearList: function (table) {
        let list = [];
        if (table.showSum) {
          //显示合计值处理
          list.push({
            label: '合计',
            value: 'sum'
          });
        }
        if (table.needLastYear == true) {
          return list.concat(this.containsLastYearList);
        }
        return list.concat(this.yearList);
      },

      downloadFile: function () {
        window.open(this.$ctx+'/compute_version/result/download?dataVersion=' + this.computeVersion.id);
      },
      downloadReportFile: function () {
        window.open(this.$ctx+'/compute_version/report/download?dataVersion=' + this.computeVersion.id);
      },
      downloadMonteCarloData: function () {
        let sheetList = [{id:'monte_carlo_data_table',name:'数据表'}];
        for(let item of this.monteCarloSummaryList) {
          sheetList.push({id:'monte_carlo_rate_analysis_'+item.ref,name:item.name+'(概率表)'});
        }
        sheetList.push({id:'monte_carlo_summary_table_'+this.computeVersion.id,name:'蒙特卡洛模拟指标汇总'});
        this.exportExcel(sheetList,"蒙特卡洛分析结果.xls");
        // window.open(this.$ctx+'/compute_version/monte_carlo/download?dataVersion=' + this.computeVersion.id);
      },
      downloadLog: function () {
        window.open('/compute_version/log/download?dataVersion=' + this.computeVersion.id);
      },
      /**
       * 初始化页面状态
       */
      initInvokeState(state,display,recordChanged) {
        if(!state) {
          state = 'record';
        }
        if(!display) {
          display = 'record';
        }
        this.invokeState = {
          state: state,
          display: display,
          recordChanged:recordChanged?true:false,
        };
      },

      loadRiskItemList() {
        this.$get("/riskAnalysis/item/data", {
          modelId: this.computeVersion.modelId,
        }, (response) => {
          let resultList = [];
          let map = {};
          for (let item of response.data) {
            let risk = {
              label: item.name,
              name: item.name,
              key: item.id,
              type: 'all'
            };
            resultList.push(risk);
            map[risk.key] = risk;
          }
          this.monteCarloConfig.riskItemList = resultList;
          this.monteCarloConfig.riskItemMap = map;

        });
      },

      //创建录入数据
      createDataList: function (sourceData) {
        if (this.inputTableList.length < 1) {
          return;
        }
        this.$set(this.computeVersion, 'evaluationPeriod', this.computeVersion.calculateYearEnd - this.computeVersion.calculateYearStart + 1);

        //初始化页面状态
        this.initInvokeState();
        this.loadingText = '正在处理...';
        this.isLoading = true;
        let data = {};
        let defaultValueSourceDataMap = {};
        // if (this.extraInitDataMap) {
        //   for (let key in this.extraInitDataMap) {
        //     //使用额外数据对字段进行默认值初始化
        //     let initDataMapList = this.extraInitDataMap[key];
        //     if(typeof initDataMapList != 'object') {
        //       defaultValueSourceDataMap[key] = initDataMapList;
        //     }
        //     if (Array.isArray(initDataMapList) && initDataMapList.length > 0) {
        //       if (initDataMapList.length > 1) {
        //         let find = false;
        //         //如果初始化数据有多份，则按照mark标记匹配
        //         for (let dataItem of initDataMapList) {
        //           if (dataItem.mark == this.computeVersion.mark) {
        //             defaultValueSourceDataMap[key] = dataItem;
        //             find = true;
        //             break;
        //           }
        //         }
        //         if (find == false) {
        //           //如果没有匹配，则为空对象
        //           defaultValueSourceDataMap[key] = {};
        //         }
        //       } else {
        //         defaultValueSourceDataMap[key] = initDataMapList[0];
        //       }
        //     } else {
        //       defaultValueSourceDataMap[key] = initDataMapList;
        //     }
        //   }
        // }

        for (let index = 0; index < this.inputTableList.length; index++) {
          let table = this.inputTableList[index];
          let inputFieldList = table.fieldList;
          let tableData = {};
          data[table.id] = tableData;

          for (let i = 0; i < inputFieldList.length; i++) {
            let field = inputFieldList[i];
            let fieldData = {};
            tableData[field.id] = fieldData;
            //字段默认填充值
            let fieldDefaultFillValue = '';
            if (field.defaultValueSource == 'input' || !field.defaultValueSource) {
              if (field.defaultValue != undefined && field.defaultValue != null) {
                fieldDefaultFillValue = field.defaultValue;
              }
            } else if(defaultValueSourceDataMap[field.defaultValueSource]){
              //使用额外数据对字段进行默认值初始化
              let initDataMap = defaultValueSourceDataMap[field.defaultValueSource];
              let yearInitDataMap = {};
              if(initDataMap.yearDataList) {
                for(let item of initDataMap.yearDataList) {
                  yearInitDataMap[item.year+''] = item;
                }
              }
              let initValue = initDataMap[field.defaultValue];
              if(initValue) {
                fieldDefaultFillValue = initValue;
              }
            }
            //添加数据复制功能，只修改评价年限，则迁移原有数据
            let copyData = null;
            if (sourceData && sourceData[table.id] && sourceData[table.id][field.id] && sourceData[table.id][field
                .id
              ]) {
              copyData = sourceData[table.id][field.id];
            }
            if (copyData && copyData['-1']) {
              fieldDefaultFillValue = copyData['-1'];
            }
            fieldData['-1'] = fieldDefaultFillValue;
            if (table.needLastYear == true) {
              let value = '';
              //如果需要上年数据，且默认值填充方式为已发生年份或所有年份包含已发生则填充
              if(field.dataFillType=='happened_year'||field.dataFillType=='all_year_with_happend') {
                 value = fieldDefaultFillValue;
              }
              fieldData[this.computeVersion.calculateYearStart - 1 + ''] = value;
            }

            //评价期年份数据填充
            let yearIndex = 0;
            //需要包含已发生年份
            for (let j = this.computeVersion.calculateYearStart-1; j <= this.computeVersion.calculateYearEnd; j++) {
              yearIndex = j-this.computeVersion.calculateYearStart+1;
              let value = '';
              //如果当前年份为第一年而且默认值填充方式为第一年，则设为默认值
              if(j == this.computeVersion.calculateYearStart&&field.dataFillType=='first_year'){
                value = fieldDefaultFillValue;
              }
              //如果默认值填充方式为所有年份、所有年份包含已发生年份，设为默认值
              if(field.dataFillType=='all_year'||field.dataFillType=='all_year_with_happend'){
                value = fieldDefaultFillValue;
              }
              if(yearInitDataMap&&yearInitDataMap[yearIndex+'']&&yearInitDataMap[yearIndex+''][field.defaultValue]){
                value = yearInitDataMap[yearIndex+''][field.defaultValue];
              }
              fieldData[j] = value;
              if (copyData && copyData[j]) {
                fieldData[j] = copyData[j];
              }
            }
          }
        }
        this.recordData = data;
        this.invokeState.state = 'record';
        this.invokeState.display = 'record';
        this.recordTabName = this.inputTableList[0].name;
        this.changeInputTab(this.recordTabName);
        this.isLoading = false;
      },
      invoke: function () {
        //修改页面状态为执行计算，展示录入标签
        this.initInvokeState('invoke');
        this.loadingText = '正在计算...';
        this.isLoading = true;

        let saveData = {};
        for (let tableId in this.recordData) {
          saveData[tableId] = {};
          for (let fieldId in this.recordData[tableId]) {
            saveData[tableId][fieldId] = {};
            for (let key in this.recordData[tableId][fieldId]) {
              if (key && isNaN(key) == false) {
                saveData[tableId][fieldId][key] = this.recordData[tableId][fieldId][key];
              }
            }
          }
        }

        this.computeVersion.dataMap = saveData;
        // this.$post("/data/compute/saveInputdata", this.computeVersion, (response) => {
        //   this.computeVersion.id = response.data;
        //   this.computeVersion.type = 'default';
        if(this.checkPermission('model:create')) {
          this.computeVersion.logDetail = true;
        }
        this.$post("/compute_version/invoke", this.computeVersion, (response) => {
          this.$message({
            message: '计算成功',
            type: 'success'
          });
          // history.pushState(null, null, "/#/evaluation/compute-invoke?id=" + this.currentProject.id + "&version=" +
          //     response.data)
          if(this.$route.query.src) {
            let currentPath = this.$route.fullPath;

            this.$emit('tab-refresh',this.$route.query.src,null,()=>{
              this.$emit('tab-active',currentPath)
            })

          }
          //计算成功后重新加载版本信息，并加载版本数据
          this.loadComputeVersionInfo(response.data,(version)=>{
            this.loadDataVersion(version.id);
          });

          // this.previewData();

        }, (response) => {
          if (response.code != 0) {
            //如果计算失败，则应展示录入参数页面
            this.initInvokeState();
            this.isLoading = false;
          } else {
            this.loadingText = '正在加载数据...';
          }
        });

        // }, (response) => {
        //   if (response.code != 0) {
        //     this.isLoading = false;
        //     this.invokeState = {state: 'record', display: 'record'};
        //   }
        // });
      },
      /**
       * 加载版本数据
       **/
      loadDataVersion(dataVersion) {
        this.loadingText = '加载数据...';
        this.isLoading = true;
        // this.$get("/data/compute/" + dataVersion, {}, (response) => {
        this.$get("/compute_version/input/" + dataVersion, {}, (response) => {
          // if (!response.data) {
          //   if(this.extraInitDataMap){
          //     this.createDataList();
          //   } else {
          //     this.loadExtraInitData(this.createDataList)
          //   }
          //   this.isLoading = false;
          //   return;
          // }
          if (!response.data) {
            this.$message.warning("未找到该版本对应录入数据")
            this.isLoading = false;
            return;
          }

          let recordData = response.data;
          // if (response.data.cutoff) {
          //   this.computeVersion.cutoff = this.cutoff;
          // }
          this.recordTabName = this.inputTableList[0].name;
          this.changeInputTab(this.recordTabName);
          if(this.computeVersion.computeTime) {
            //修改页面状态为计算完成，展示结果页
            this.initInvokeState('complete', 'result');
          }
          for (let table of this.inputTableList) {
            if (recordData[table.id] == undefined) {
              recordData[table.id] = {};
            }
            for (let field of table.fieldList) {
              if (recordData[table.id][field.id] == undefined) {
                let fieldData = {};
                recordData[table.id][field.id] = fieldData;
                if (table.single) {
                  fieldData['-1'] = '';
                } else {
                  let list = this.getYearList(table);
                  for (let year of list) {
                    fieldData['' + year.value] = '';
                  }
                }

              } else {
                if (recordData[table.id] && recordData[table.id][field.id]) {
                  if (table.single && recordData[table.id][field.id]['-1']!=undefined) {
                    // recordData[table.id][field.id]['-1'] = recordData[table.id][field.id]['' + this.computeVersion.calculateYearStart];
                    recordData[table.id][field.id]['-1'] = recordData[table.id][field.id]['-1'];
                  }
                  this.sumAllYearValue(table, field, recordData);
                }
              }
            }
          }

          this.recordData = recordData;
          if(this.computeVersion.computeTime) {
            this.previewData();
          } else {
            this.isLoading = false;
          }
        }, (response) => {
          if (response.code != 0) {
            this.isLoading = false;
          }
        });
      },
      handlePaste: function (event, tableId, fieldId, year) {
        //处理来自excel的粘贴数据
        let text = event.clipboardData.getData('text');
        if (!text || text == '') {
          return;
        }
        let rows = text.split('\n');
        let data = [];
        for (let i = 0; i < rows.length; i++) {
          let cols = rows[i].split("\t");
          data.push(cols);
        }
        if (data.length <= 0) {
          return;
        }

        let table = this.inputTableMap[tableId];
        if (!table) {
          return;
        }

        let sumFieldMap = {};
        for (let j = 0; j < table.fieldList.length; j++) {
          let field = table.fieldList[j];
          if (field.id == fieldId) {
            for (let k = 0; k < data.length; k++) {
              if (k + year > this.computeVersion.calculateYearEnd) {
                break;
              }
              for (let l = 0; l < data[k].length; l++) {
                if (j + l >= table.fieldList.length) {
                  break;
                }
                let targetField = table.fieldList[j + l];
                sumFieldMap[targetField.id] = targetField;
                let val = data[k][l].trim();
                if (targetField.dataType && targetField.dataType == 'number') {
                  val = val.replace(/[^\d.]/g, '');
                }
                this.recordData[tableId][targetField.id][year + k] = val;
              }
            }
            break;
          }
        }
        if (table.showSum) {
          for (let fId in sumFieldMap) {
            this.sumAllYearValue(table, sumFieldMap[fId], this.recordData);
          }
        }

      },
      handleCopy: function (event) {
        if (!this.selectArea || !this.selectArea.tableId) {
          return;
        }
        //处理来自excel的粘贴数据
        // let text = event.clipboardData.getData('text');


        let table = this.inputTableMap[this.selectArea.tableId];
        if (!table) {
          return;
        }
        let data = '';
        for (let i = this.selectArea.beginYear; i <= this.selectArea.endYear; i++) {
          let line = '';
          for (let field of table.fieldList) {
            if (!line && field.id != this.selectArea.beginField) {
              continue;
            }
            line += this.recordData[table.id][field.id][i + ''];
            if (field.id == this.selectArea.endField) {
              break;
            }
            line += '\t';
          }
          data += line;
          if (i == this.selectArea.endYear) {
            break;
          }
          data += '\n';
        }
        this.$copyText(data).then(function (e) {
          console.log("内容已复制")
          // console.log(e)
        }, function (e) {
          alert('无法复制')
          console.log(e)
        })

      },
      handleMouseDown: function (event, tableId, fieldId, year) {
        if (this.selectArea && !this.selectArea.selecting && event.shiftKey) {
          this.selectArea.selecting = true;
          return true;
        }
        this.selectArea = {
          beginYear: year,
          beginField: fieldId,
          tableId: tableId,
          cellMap: null,
          selecting: true,
        };
        return true;
      },
      handleMouseMove: function (event, tableId, fieldId, year) {
        if (!this.selectArea || this.selectArea.tableId != tableId) {
          return;
        }
        if (!this.selectArea.selecting) {
          //未选择起始格/选择已结束，忽略
          return;
        }
        if (this.selectArea.currentField == fieldId && this.selectArea.currentYear == year) {
          //本次位置与上次相同，不做处理
          return;
        }
        this.selectArea.currentField = fieldId;
        this.selectArea.currentYear = year;
        if (this.updateAreaTask != null) {
          clearTimeout(this.updateAreaTask);
        }
        this.updateAreaTask = setTimeout(() => {
          let area = this.caculateSelectArea(tableId, this.selectArea.beginField, this.selectArea.beginYear,
            fieldId, year);
          this.selectArea.cellMap = area.cellMap;
          this.updateAreaTask = null;
        }, 10)


      },
      handleEscClick: function (event, tableId, fieldId, year) {
        this.selectArea = {};
      },
      //监听删除按钮按下，批量删除选中区域数据
      handleDeleteClick: function (event, tableId, fieldId, year) {
        if (!this.selectArea || !this.selectArea.cellMap) {
          return;
        }
        let tableRecord = this.recordData[this.selectArea.tableId];
        for (let key in this.selectArea.cellMap) {
          if (!key) {
            continue;
          }
          let tmpArray = key.split("\:");

          if (!tmpArray || tmpArray.length < 2) {
            continue;
          }
          let fieldId = tmpArray[0];
          let year = tmpArray[1];


          if (!tableRecord) {
            continue;
          }
          if (!tableRecord[fieldId]) {
            continue;
          }
          tableRecord[fieldId][year] = '';
        }
        //更新合计行数据
        let table = this.inputTableMap[tableId];

        if (!table || !table.showSum) {
          return;
        }
        let find = false;
        for (let field of table.fieldList) {
          if (!find && field.id != this.selectArea.beginField) {
            continue;
          }
          find = true;
          this.sumAllYearValue(table, field, this.recordData);
          if (field.id == this.selectArea.endField) {
            break;
          }
        }
        this.selectArea = {};

      },
      //监听回车按钮按下，输入框焦点下移
      handleEnterClick: function (event, tableId, fieldId, year) {
        let input = document.getElementById('input:' + tableId + ':' + fieldId + ':' + (year + 1));
        if (input) {
          input.focus()
        }

      },
      handleLeaveTable: function (event) {
        if (!this.selectArea) {
          return;
        }
        this.selectArea.selecting = false;
      },
      handleMouseUp: function (event, tableId, fieldId, year) {
        if (!this.selectArea || !this.selectArea.tableId) {
          return;
        }
        this.selectArea.selecting = false;
        if (this.selectArea.tableId != tableId) {
          return;
        }

        if (this.updateAreaTask != null) {
          clearTimeout(this.updateAreaTask);
        }
        let area = this.caculateSelectArea(tableId, this.selectArea.beginField, this.selectArea.beginYear, fieldId,
          year);
        this.selectArea.beginYear = area.beginYear;
        this.selectArea.endYear = area.endYear;
        this.selectArea.beginField = area.beginField;
        this.selectArea.endField = area.endField;
        this.selectArea.cellMap = area.cellMap;


        return true;
      },
      caculateSelectArea: function (tableId, field1, year1, field2, year2) {
        let table = this.inputTableMap[tableId];
        if (!table) {
          return {};
        }
        //需要考虑选取方向，可能左上至右下，右上至左下，右下至左上，左下至右上
        //超出选择界限
        let selectFieldArray = [];
        let fieldBound = {
          begin: null,
          end: null
        };
        if (field1 == field2) {
          fieldBound.begin = field1;
          fieldBound.end = field1;
        } else {
          for (let field of table.fieldList) {
            if (field.id != field1 && field.id != field2) {
              continue;
            }
            if (!fieldBound.begin) {
              fieldBound.begin = field.id;
            } else {
              fieldBound.end = field.id;
            }
          }
        }
        for (let field of table.fieldList) {
          if (selectFieldArray.length <= 0 && field.id != fieldBound.begin) {
            continue;
          }
          selectFieldArray.push(field);
          if (field.id == fieldBound.end) {
            break;
          }
        }
        let beginYear = year1 > year2 ? year2 : year1;
        let endYear = year1 < year2 ? year2 : year1;
        let map = {};
        if (beginYear != endYear || field1 != field2) {
          for (let field of selectFieldArray) {
            for (let i = beginYear; i <= endYear; i++) {
              map[field.id + ":" + i] = true;
            }
          }
        }

        return {
          beginYear: beginYear,
          endYear: endYear,
          beginField: fieldBound.begin,
          endField: fieldBound.end,
          cellMap: map
        };
      },

      changeInputTab: function (tab) {

        for (let table of this.inputTableList) {
          if (table.name == tab) {
            if (table.single) {
              let maxLength = 0;
              for (let field of table.fieldList) {
                let length = this.judgeColumnWidth(field.name);
                if (length > maxLength) {
                  maxLength = length;
                }
              }
              this.formLabelWidth = maxLength;
            }
            break;
          }
        }
        //清空选择区域
        this.selectArea = {};
      },
      /**
       * 数据向下填充功能实现
       */
      fillDataToBottom: function () {
        let tableId = this.fillDownOption.tableId;
        let fieldId = this.fillDownOption.fieldId;
        let currentYear = this.fillDownOption.year;
        if (!tableId || tableId == '' || !fieldId) {
          return;
        }
        let table = this.inputTableMap[tableId];
        if (!table) {
          return;
        }
        let bound = {
          begin: fieldId,
          end: fieldId
        };
        if (this.selectArea && this.selectArea.beginYear &&
          this.selectArea.beginYear == this.selectArea.endYear &&
          this.selectArea.endField) {
          //如果有选中区域，则可批量向下填充
          bound = {
            begin: this.selectArea.beginField,
            end: this.selectArea.endField
          };
        }
        let start = false;
        for (let field of table.fieldList) {
          if (start == false && field.id != bound.begin) {
            continue;
          }
          start = true;
          for (let k = currentYear + 1; k <= this.computeVersion.calculateYearEnd; k++) {
            this.recordData[tableId][field.id][k] = this.recordData[tableId][field.id][currentYear];
          }
          this.sumAllYearValue(table, field, this.recordData);
          if (field.id == bound.end) {
            break;
          }
        }

      },
      /**
       * 计算列宽
       * @param text
       * @returns {number}
       */
      judgeColumnWidth: function (text) {
        let array = text.split('');
        let length = 0;
        for (let char of array) {
          if (escape(char).indexOf("%u") < 0) {
            length++;
          } else {
            length += 2;
          }
        }
        return (length + 4) * 7;
      },
      /**
       * 查找某列合理的最长字符串
       * @param text
       * @returns {number}
       */
      judgeLongestColumnWidth: function (col, dataList) {
        let text = '默认字';
        let text2 = '默认字';
        if (col == undefined || dataList == undefined) {
          return text;
        }
        for (let item of dataList) {
          let data = item[col];
          if (data && data.startsWith('data:image')) {
            continue;
          }
          if (data) {
            data = data.trim();
          }
          if (data != undefined && data.length > text.length) {
            text = data;
          } else if (data != undefined && data.length > text2.length) {
            text2 = data;
          }
        }

        if (text.length > text2.length * 2) {
          //如果排名第一的字符串长度超过第二的字符串长度3倍，则认为不合理
          text = text2;
        }
        return this.judgeColumnWidth(text);
      },
      recordTableLabelSpanMethod: function ({
        row,
        column,
        rowIndex,
        columnIndex
      }, table) {
        let cacheKey = table.id + this.computeVersion.buildYearCount + ':' + this.computeVersion.calculateYearEnd +
          ':' + rowIndex + ':' + columnIndex;
        if (this.recordTableLabelSpanCache[cacheKey]) {
          return this.recordTableLabelSpanCache[cacheKey];
        }
        let common = {
          rowspan: 1,
          colspan: 1
        };
        if (columnIndex > 1) {
          this.recordTableLabelSpanCache[cacheKey] = common;
          return;
        }
        if (columnIndex === 1) {
          if (rowIndex == 0 && table.showSum) {
            this.recordTableLabelSpanCache[cacheKey] = {
              rowspan: 1,
              colspan: 0
            };
          } else {
            this.recordTableLabelSpanCache[cacheKey] = common;
          }
          return this.recordTableLabelSpanCache[cacheKey];
        }
        let extralYear = table.needLastYear == true ? 1 : 0;
        if (table.showSum) {
          extralYear++;
        }
        if (table.needLastYear) {
          extralYear++;
        }
        // let haveLabelSpan = this.computeVersion.buildYearCount&&this.computeVersion.buildYearCount>0;
        let buildYearCount = 0;
        if (this.computeVersion.buildYearCount) {
          buildYearCount = this.computeVersion.buildYearCount;
        }

        if (rowIndex < extralYear) {
          let colspan = 1;
          if (rowIndex == 0 && table.showSum) {
            if (columnIndex == 0) {
              colspan = 2;
            }
          }
          this.recordTableLabelSpanCache[cacheKey] = {
            rowspan: 1,
            colspan: colspan
          };
        } else if (rowIndex == extralYear && buildYearCount > 0) {
          this.recordTableLabelSpanCache[cacheKey] = {
            rowspan: buildYearCount,
            colspan: 1
          };
        } else if (rowIndex == (buildYearCount + extralYear)) {
          this.recordTableLabelSpanCache[cacheKey] = {
            rowspan: this.computeVersion.calculateYearEnd - this.computeVersion.calculateYearStart + 1 -
              buildYearCount,
            colspan: 1
          };
        } else {
          this.recordTableLabelSpanCache[cacheKey] = {
            rowspan: 0,
            colspan: 1
          };
        }
        return this.recordTableLabelSpanCache[cacheKey];

      },
      // 横向合并头部单元格
      discountHeaderStyle1: function ({
        row,
        column,
        rowIndex,
        columnIndex
      }) {
        let result = {'border-color':'#ccc'};
        if (rowIndex === 1) { //判断当rowIndex = 1 时隐藏另外领两个头部单元格
          result.display='none';
        }
        return result;
      },
      previewData: function () {
        if(!this.computeVersion.computeTime){
          return;
        }
        this.loadingText = '正在加载...';
        this.isLoading = true;
        // this.$get("/data/compute/preview?dataVersion=" + this.computeVersion.id, {}, (response) => {
        this.$get("/compute_version/result/preview?dataVersion=" + this.computeVersion.id, {}, (response) => {

          this.exportPreviewData = response.data;
          //初始化页面状态为计算完成，展示结果标签页
          this.initInvokeState('complete','result');
          this.isLoading = false;
        }, (response) => {
          if (response.code != 0) {
            this.initInvokeState();
          }
          this.isLoading = false;
        });
      },
      recordTableRowClassName({
        row,
        rowIndex
      }) {
        if (row.label == '建设期') {
          return 'buildyear-row';
        } else {
          return 'caculateyear-row';
        }
        return '';
      },

      processInputValue: function (table, field, year, value) {
        this.invokeState.recordChanged = true;
        value = value.replace(/[^\d.]/g, '');
        this.recordData[table.id][field.id][year] = value;
        this.sumAllYearValue(table, field, this.recordData);
      },
      sumAllYearValue: function (table, field, dataMap) {
        if (!table.showSum || !field.showSum) {
          return;
        }
        let total = 0;
        let maxDigit = 0;
        for (let yearItem of this.getYearList(table)) {
          let val = dataMap[table.id][field.id][yearItem.value];
          if (isNaN(yearItem.value) == false && isNaN(val) == false) {
            total += Number(val);
            let dotIndex = val.indexOf('.');
            if (dotIndex >= 0) {
              let digit = val.length - dotIndex - 1;
              if (digit > maxDigit) {
                maxDigit = digit;
              }
            }
          }
        }
        dataMap[table.id][field.id]['sum'] = total.toFixed(maxDigit);
      },
      showCellDetail: function (sheetName, row, column) {
        this.detailCellIndex = sheetName + '_' + row.rowNum + '_' + column.property;
      },
      openMonteCarloDlg() {
        this.monteCarloConfig.configDlgVisible = true;
      },
      openMultiPriceDlg() {
        this.multiPriceConfig.configDlgVisible = true;
      },
      addMultiPrice() {
        let priceList = this.multiPriceConfig.priceList;
        if (!priceList || priceList == null) {
          priceList = [];
        }
        let newItem = {
          index: priceList.length +1
        }
        priceList.push(newItem);

      },
      //计算多油价
      computeMultiPrice() {
        let priceList = this.multiPriceConfig.priceList;
        let priceParam = '&prices=';
        for(let item of priceList) {
          if (!item.price || item.price == null || item.price =='') {
            continue;
          }
          priceParam+=item.price+',';
        }
        priceParam = priceParam.substring(0,priceParam.length-1);
        window.open(this.$ctx + "/compute_version/download/multi_oil_price?dataVersion="+this.computeVersion.id+priceParam);

      },
      //计算蒙特卡洛
      computeMonteCarlo() {

        let dataMap = {};
        for (let item of this.monteCarloConfig.riskItemList) {
          if (item.type != 'all') {
            let config = JSON.parse(JSON.stringify(item.config));
            config.type = item.type;
            dataMap[item.key] = config;
          }
        }
        this.monteCarloConfig.isLoading = true;
        this.$post("/compute_version/monte_carlo/result?dataVersion=" + this.computeVersion.id,
          dataMap, (response) => {

            this.$message({
              message: response.msg,
              type: 'success'
            });


            this.monteCarloSummaryList = response.data.dataList;

            let offsetMap = {};
            let compareMap = {};
              let analysisDataListMap = {};
              let itemDataList = [];
              if(this.monteCarloSummaryList&&this.monteCarloSummaryList.length>0) {
                let count = this.monteCarloSummaryList[0].dataList.length;
                for(let i=0;i<count;i++) {
                  let row = {};
                  for (let item of this.monteCarloSummaryList) {
                    if(item.dataList&&item.dataList.length>i) {
                      row[item.ref] = item.dataList[i];
                    }
                  }
                  itemDataList.push(row);
                }
              }
              this.monteCarloItemDataList = itemDataList;
            for (let item of this.monteCarloSummaryList) {
              let legendList = [];
              let offset = (item.max - item.min) / 40;
              if (offset == 0) {
                continue;
              }
              offsetMap[item.ref] = offset;
              compareMap[item.ref] = {};
              analysisDataListMap[item.ref] = [];
              for (let i = 0; i < 40; i++) {
                let value = (item.min + offset * i - offset / 2).toFixed(5);
                legendList.push(value)
                analysisDataListMap[item.ref].push({range:(parseFloat(value) - offset / 2).toFixed(5) + '~' +
                      (parseFloat(value) + offset / 2).toFixed(5)});
                compareMap[item.ref][i] = value > item.baseValue;
              }
              let rateMap = {};
              for (let tmp of item.dataList) {
                let index = parseInt((tmp - item.min) / offset);
                if (index >= 40) {
                  index = 40;
                }
                if (!rateMap[index]) {
                  rateMap[index] = 0;
                }
                rateMap[index] = rateMap[index] + 1;
              }

              let chartDataList = [];
              for (let i = 0; i < 40; i++) {
                let rate = 0;
                if (rateMap[i]) {
                  rate = rateMap[i] / item.dataList.length;
                }
                analysisDataListMap[item.ref][i].rate = rate;
                chartDataList.push(rate)
              }
              this.monteCarloChartOptionMap[item.ref] = {
                title: {
                  text: item.name,
                  subtext: item.keyword,
                  x: 'center'
                },
                tooltip: {
                  trigger: "axis",
                  axisPointer: {
                    type: "shadow",
                  },
                  formatter: function (params) {
                    let param = params[0];

                    let htmlStr = '<div style="text-align: left;">';
                    let offset = offsetMap[param.seriesId];

                    //添加一个汉字，这里你可以格式你的数字或者自定义文本内容
                    htmlStr += '范围:' + (parseFloat(param.axisValue) - offset / 2).toFixed(5) + '~' +
                      (parseFloat(param.axisValue) + offset / 2).toFixed(5) +
                      '<br>概率:' + param.value;


                    htmlStr += '</div>';

                    return htmlStr;
                  }
                },
                grid: {
                  bottom: "3%",
                  left: '3%',
                  right: '3%',
                  containLabel: true,
                },
                xAxis: {
                  type: "category",
                  // boundaryGap: [0, 0],
                  boundaryGap: true,
                  axisLabel: {
                    interval: 0,
                    rotate: '90',
                    //     formatter: function (value) {
                    //     return value.split("").join("\n");
                    // }
                  },
                  data: legendList,
                  axisTick: {
                    alignWithLabel: true
                  }
                },
                yAxis: {
                  type: "value"
                },
                series: [{
                  name: item.name,
                  id: item.ref,
                  refData: item,
                  type: "bar",
                  data: chartDataList,
                  itemStyle: {
                    normal: {
                      color: function (params) {
                        if (compareMap[params.seriesId][params.dataIndex]) {
                          return '#5CB87A';
                        }
                        return '#C1232B';

                      },

                    }
                  },
                }, ],
              }
            }

            this.monteCarloRateAnalysisMap = analysisDataListMap;
            this.monteCarloConfig.configDlgVisible = false;
            this.monteCarloConfig.monteCarloResultVisible = true;

          }, () => {
            this.monteCarloConfig.isLoading = false;
          });
      },
      updateDistItem(type) {
        if (type == 'triangular-add') {
          let list = this.$refs['all_risk_panel'].getChecked();
          for (let id of list) {
            this.monteCarloConfig.riskItemMap[id].type = 'triangular';
          }
        } else if (type == 'triangular-remove') {
          let list = this.$refs['triangular_risk_panel'].getChecked();
          for (let id of list) {
            let item = this.monteCarloConfig.riskItemMap[id];
            item.type = 'all';
            item.label = item.name;
            item.config = {};
          }
        }
        if (type == 'normal-add') {
          let list = this.$refs['all_risk_panel'].getChecked();
          for (let id of list) {
            this.monteCarloConfig.riskItemMap[id].type = 'normal';
          }
        } else if (type == 'normal-remove') {
          let list = this.$refs['normal_risk_panel'].getChecked();
          for (let id of list) {
            let item = this.monteCarloConfig.riskItemMap[id];
            item.type = 'all';
            item.label = item.name;
            item.config = {};
          }
        }

      },
      updateRiskItemSetting(formName) {
        if (formName == 'triangular-from') {
          let list = this.$refs['triangular_risk_panel'].getChecked();
          for (let id of list) {
            let item = this.monteCarloConfig.riskItemMap[id];
            let setting = this.monteCarloConfig.triangularSetting;
            item.config = {};
            item.config.lowerLimit = (parseFloat(setting.lowerLimit) / 100).toFixed(2);
            item.config.upperLimit = (parseFloat(setting.upperLimit) / 100).toFixed(2);
            item.config.most = (parseFloat(setting.most) / 100).toFixed(2);
            item.label = item.name + ' (' + item.config.lowerLimit + '/' + item.config.most + '/' + item.config
              .upperLimit + ')';
          }
        } else if (formName == 'normal-form') {
          let list = this.$refs['normal_risk_panel'].getChecked();
          for (let id of list) {
            let item = this.monteCarloConfig.riskItemMap[id];
            let setting = this.monteCarloConfig.normalSetting;
            item.config = {};
            item.config.mean = parseFloat(setting.mean).toFixed(2);
            item.config.std = parseFloat(setting.std).toFixed(2);
            item.label = item.name + ' (' + item.config.mean + '/' + item.config.std + ')';
          }
        }
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      loadInputInfo(computeVersion) {
        this.$get('/table/fulldata', {
          modelId: computeVersion.modelId
        }, (response) => {
          this.inputTableList = response.data;
          for (let i = 0; i < response.data.length; i++) {
            let table = response.data[i];
            let fieldList = [];
            for (let j = 0; j < table.fieldList.length; j++) {
              let field = table.fieldList[j];
              // if (field.show == false) {
              //   continue;
              // }
              let label = field.name;
              if (field.unit && field.unit != '') {
                label += '(' + this.unitTypeMap[field.unit] + ')';
              }
              field.label = label;
              fieldList.push(field);
            }
            table.fieldList = fieldList;
          }

          let tableList = this.inputTableList;
          let tableMap = {};
          for (let table of tableList) {
            if (table.single) {
              if (!table.displayColumn || table.displayColumn < 1) {
                table.displayColumn = 3;
              }
            }
            tableMap[table.id] = table;
          }
          this.inputTableMap = tableMap;
          if (computeVersion.id && computeVersion.id != '') {
            this.loadDataVersion(computeVersion.id);
          }
          // else {
          //   if(this.extraInitDataMap){
          //     this.createDataList();
          //   } else {
          //     this.loadExtraInitData(this.createDataList)
          //   }
          // }

          // this.isLoading = false;
          this.loadRiskItemList();
        });
      },
      openSaveDlg() {
        this.detailDlgVisible = true;
      },
      // /**
      //  * 保存结果
      //  */
      // saveResult() {
      //
      //   let versionData = JSON.parse(JSON.stringify(this.computeVersion));
      //   this.$post("/compute_version/save_temp", versionData, (response) => {
      //     // this.computeVersion.id = response.data;
      //     this.detailDlgVisible = false;
      //     this.$message.success('保存成功！');
      //     this.loadComputeVersionInfo(this.sourceComputeVersion,(version)=>{
      //       history.pushState(null, null, "/#/evaluation/compute-invoke?id=" + this.currentProject.id + "&version=" +
      //           this.computeVersion.id)
      //       this.loadDataVersion(version.id);
      //     });
      //
      //
      //   });
      // },
      /**
       * 复制版本数据
       */
      copyVersion() {

        this.isLoading = true;
        this.computeVersion.projectId = this.currentProject.id;
        let versonData = JSON.parse(JSON.stringify(this.computeVersion));
        versonData.type = 'default';
        this.$post("/compute_version/copy", versonData, (response) => {
          // this.computeVersion.id = response.data;
          this.detailDlgVisible = false;
          this.$message.success('保存成功！');
          this.computeVersion.type = 'default';
          this.sourceComputeVersion = this.computeVersion.id;
          this.changeComputeVersion(response.data);

        },(response)=>{
          this.isLoading = false;
        });
      },
      auditVersion(pass) {
        this.computeVersion.pass = pass;
        let data = {};
        data.computeVersion = this.computeVersion.id;
        data.pass = pass;
        // this.$post("/compute_version_state/audit", this.computeVersion, (response) => {
        this.$post("/project/report_version/audit", data, (response) => {
          this.$message.success('操作成功！');
          this.loadDataVersion(this.sourceComputeVersion);
          this.loadProjectInfo(this.currentProject.id);
        });
      },
      loadProjectInfo(id) {
        this.$get("/project_info/info/" + id, {}, (response) => {
          this.currentProject = response.data;
          this.currentProjectName = this.currentProject.name;
          this.$emit('add-bread', {
            name: this.currentProject.name
          })
        });
      },
      /**
       * 加载额外初始化数据,需要保证在加载完版本信息后执行
       * @param hook 回调函数
       */
      // loadExtraInitData(hook) {
        // this.isLoading = true;
        // this.$get("/data/default_value", {
        //   projectId: this.computeVersion.projectId,
        //   costStandardYear: this.computeVersion.costStandardYear
        // }, (response) => {
        //   this.extraInitDataMap = response.data;
        // },()=>{
        //   if(hook){
        //     hook();
        //   }
        // });
      // },
      /**
       * 监听指令执行
       * @param command
       */
      handleCommand(command) {
        if(command) {
          eval('this.'+command+'()');
        }
      },
      /**
       * 加载计算版本信息
       * @param versionId 版本id
       * @param hook 获取成功后的回调函数
       */
      loadComputeVersionInfo(versionId,hook) {
        this.$get("/compute_version/info/" + versionId, {}, (response) => {
          this.computeVersion = response.data;
          this.readonly = this.computeVersion.type!='default';
          if(!this.computeVersion||!this.computeVersion.id) {
            //如果版本不存在，则跳转到版本列表页
            this.openPage('/evaluation/compute-version-list',this.$route.query.id);
            return;
          }
          this.$set(this.computeVersion,'evaluationPeriod', this.computeVersion.calculateYearEnd - this.computeVersion.calculateYearStart + 1);
          if(hook) {
            hook(response.data)
          }
        });
      },
      /**
       * 调用拉齐计算接口
       */
      cashFlowPull() {
        //修改页面状态为执行计算，展示录入标签
        this.initInvokeState('invoke');
        this.loadingText = '正在计算...';
        this.isLoading = true;
        this.$post("/compute_version/cash_flow_pull", this.computeVersion, (response) => {
          this.$message({
            message: '计算成功',
            type: 'success'
          });
          history.pushState(null, null, "/#/evaluation/compute-invoke?id=" + this.currentProject.id + "&version=" +
              response.data)
          this.loadingText = '正在加载数据...';
          this.loadComputeVersionList(this.computeVersion.projectId);
          this.loadComputeVersionInfo(response.data,(version)=>{
            this.loadDataVersion(version.id);
          },(response)=>{
            if (response.code != 0) {
              //如果计算失败，则应展示录入参数页面
              this.initInvokeState("complete","result");
              this.isLoading = false;
            }
          });
        },(response)=>{
          if (response.code != 0) {
            //如果计算失败，则应展示录入参数页面
            this.initInvokeState("complete","result");
            this.isLoading = false;
          }
        });
      },
      //加载评价版本,并将其展开
      loadComputeVersionList(projectId) {
        this.$get("/compute_version/data", {projectId:projectId,pageSize:-1}, (response) => {
          let list = [];
          for (let item of response.data) {
            list.push(item);
            if (item.children && item.children.length > 0) {

              for (let child of item.children) {
                child.name = child.name;
                list.push(child);
              }
            }
          }
          this.computeVersionList = list;
        }, () => {
        });
      },
      //切换评价版本操作
      changeComputeVersion(versionId) {
        let version = null;
        for(let item of this.computeVersionList) {
          if(item.id==versionId) {
            version = item;
          }
        }
        if(!version) {
          console.log("未找到该版本:"+versionId);
          return;
        }
        let oldVersionId=this.$route.query.version;
        let path = this.$route.fullPath;
        if(version.mark=='result') {
          this.closePage(path);
          this.openPage('/evaluation/compute-subtract',version.projectId,{version:version.id});
          this.computeVersion.id = oldVersionId;
        } else {
          this.isLoading = true;
          history.pushState(null, null, "/#/evaluation/compute-invoke?id=" + version.projectId + "&version=" +
              versionId);
          this.init(version.projectId,versionId);
        }
      },
      /**
       * 导出录入数据按钮方法
       */
      exportInputData(){
        let data = [];
        for (let table of this.inputTableList){
          data.push({id:'t'+table.id,name:table.name})
        }
        this.exportExcel(data,'录入数据导出');
      },

      //生成报告
      // createReport() {
      //   this.loadingText = '正在计算...';
      //   const loading = this.openLoading("正在处理,请稍后...");
      //   this.$get("/project/report/createReport?versionId=" + this.computeVersion.id, {}, (response) => {
      //     this.$message.success('保存成功！');
      //   },()=>{
      //     loading.close();
      //   });
      // },

      // downloadReport(){
      //   window.open(this.$ctx+'/project/report/download?versionId=' + this.computeVersion.id);
      // },
    }


  }
</script>